package Servlet;

import DAO.BaseJdbc;
import DAO.MessageDAO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name= "delArticleServlet",value = "/delArticleServlet")
public class delArticleServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        String ArticleID = request.getParameter("ArticleID");
        MessageDAO messageDAO=new MessageDAO();

        if(messageDAO.delArticle(ArticleID)){
            response.getWriter().print("ID为"+ArticleID+"的文章已被删除！");
        }
        else {
            response.getWriter().print("删除失败！");
        }
        try {
            BaseJdbc.close(messageDAO.conn);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
}

